//电机外部控制
#include "Motor_Control.h"
#include "tim.h"
Motor_Control_t control_pulse;
 float pwm_value=0.0;
/// @brief 外部电机控制输入初始化
/// @param  
void MotorControl_Init(void)
{
  HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_1);
	HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_2);
}

/// @brief 定时器捕获回调
/// @param htim 
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
	if(htim == &htim2)
	{
		if(htim2.Channel == HAL_TIM_ACTIVE_CHANNEL_1)
		{
			control_pulse.pulse.pulse_value = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_1);
			if(control_pulse.pulse.pulse_value !=0 && control_pulse.pulse.period_value != 0)
			{
				control_pulse.pulse.duty_cycle = (control_pulse.pulse.pulse_value / (float)control_pulse.pulse.pulse_value) * 100.0;
			}
		}
		else if(htim2.Channel == HAL_TIM_ACTIVE_CHANNEL_2)
		{
			control_pulse.pulse.pulse_value = HAL_TIM_ReadCapturedValue(&htim2,TIM_CHANNEL_2);
		}
	}
}